<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<%@include file="../common/mastertopedit.jsp"%>
<input type="hidden" id="itemId" value="${model.setupItem.id}">
<div class="form-horizontal pt-15  form-clean-magin" id="content">

	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">归属门店</label>
		<div class="col-xs-9">
			<select name="shopId"
					id="shopId" class="form-control form-control-260  pull-left">
					<option value=""
						<c:if test="${model.setupItem.shopId==null}">selected="selected"</c:if>>请选择</option>
					<c:forEach items="${model.shopInfos}" var="lo" varStatus="itemStatus">
						<option value="${lo.id}"
							<c:if test="${model.setupItem.shopId==lo.id}">selected="selected"</c:if>>${lo.shopName}</option>
					</c:forEach>
				</select>
	<i class="plum-sign-right">*</i>
		</div>
	</div>
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">商品编码</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				id="itemCode" placeholder="商品编码 " value="${model.setupItem.itemCode}">
			<i class="plum-sign-right">*</i>
		</div>
	</div>

	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">商品名称</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" id="itemName" placeholder="商品名称 " 
				type="text" value="${model.setupItem.itemName}"> <i
				class="plum-sign-right">*</i>
		</div>
	</div>

	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">国际条码</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" id="barCode"
				pattern="/[^\d]+/" type="text"
				placeholder="国际条码" value="${model.setupItem.barCode}">
		</div>
	</div>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">零售价</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" id="salePrice"
				float="2"
				pattern="/[^\d\.]+/"
				type="text" placeholder="零售价" value="${model.price}"> <i
				class="plum-sign-right">*</i>
		</div>
	</div>
	
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">是否有安装费用</label>
		<div class="line-2box col-xs-9">
			<label class="radio-inline"> <input name="isSetupPrice"
				type="radio"
				<c:if test="${model.setupItem.isSetupPrice==1}">checked="checked"</c:if>
				value="1"> 有
			</label> <label class="radio-inline"> <input name="isSetupPrice"
				type="radio"
				<c:if test="${model.setupItem.isSetupPrice==0}">checked="checked"</c:if>
				value="0"> 无
			</label>
		</div>
	</div>
	
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">安装费用</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" id="setupPrice"
				float="2"
				pattern="/[^\d\.]+/"
				type="text" placeholder="安装费用" value="${model.setupItem.setupPrice}"> <i
				class="plum-sign-right">*</i>
		</div>
	</div>
	
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">商品类型</label>
		<div class="line-2box col-xs-9">
			<label class="radio-inline"> <input name="itemType"
				type="radio"
				<c:if test="${model.setupItem.itemType==0}">checked="checked"</c:if>
				value="0">不管库存 
			</label> <label class="radio-inline"> <input name="itemType"
				type="radio"
				<c:if test="${model.setupItem.itemType==1}">checked="checked"</c:if>
				value="1">管库存
			</label>
		</div>
	</div>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">商品源</label>
		<div class="line-2box col-xs-9">
			<label class="radio-inline"> <input name="deliveryType"
				type="radio"
				<c:if test="${model.setupItem.deliveryType==1}">checked="checked"</c:if>
				value="1">门店发货 
			</label> <label class="radio-inline"> <input name="deliveryType"
				type="radio"
				<c:if test="${model.setupItem.deliveryType==2}">checked="checked"</c:if>
				value="2">仓库配送
			</label>
			 <label class="radio-inline"> <input name="deliveryType"
				type="radio"
				<c:if test="${model.setupItem.deliveryType==3}">checked="checked"</c:if>
				value="3">供应商发货
			</label>
		</div>
	</div>
	
<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">图片名称</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" id="itemUrl" placeholder="图片名称 " 
				type="text" value="${model.setupItem.itemUrl}"> <i
				class="plum-sign-right">*</i>
		</div>
	</div>
	
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">商品描述</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" id="itemDesc" placeholder="商品描述" 
				type="text" value="${model.setupItem.itemDesc}"> <i
				class="plum-sign-right">*</i>
		</div>
	</div>


	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">品牌相关邮箱</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" id="email"
				type="text" placeholder="邮箱" value="${model.setupItem.email}"> <i
				class="plum-sign-right">*</i>
		</div>
	</div>



</div>
<div class="form-group text-center">
	<button type="button" class="runmi-btn runmi-primary"
		onclick="backIndex()">取消</button>
	<button type="button" class="runmi-btn runmi-sure-btn" onclick="save()">保存</button>
</div>

<script type="text/javascript">
	function save() {
		var postData = "&itemId=" + $('#itemId').val();
		
		
		var shopId= $('#shopId').val();
		if (shopId == '') {
			layer.alert('请选择门店');
			return;
		}
		postData = postData + "&shopId=" + encodeURIComponent(shopId);

		var itemCode = $('#itemCode').val();
		if (itemCode == '') {
			layer.alert('请输入商品编码');
			return;
		}
		postData = postData + "&itemCode=" + encodeURIComponent(itemCode);


		var itemName = $('#itemName').val();
		if (itemName == '') {
			layer.alert('请输入商品名称');
			return;
		}
		postData = postData + "&itemName=" + encodeURIComponent(itemName);


		var barCode = $('#barCode').val();
		if (barCode == '') {
			layer.alert('请输入商品条码');
			return;
		}
		postData = postData + "&barCode=" + encodeURIComponent(barCode);
		
		var salePrice=$('#salePrice').val();
		if (salePrice == '') {
			layer.alert('请输入零售价');
			return;
		}
		postData = postData + "&salePrice=" + encodeURIComponent(salePrice);
		

		var isSetupPrice= $("input[name='isSetupPrice']:checked").val();
		if(isSetupPrice!=undefined){
			postData=postData + "&isSetupPrice=" + isSetupPrice;
		}
		if(isSetupPrice=='1'){
			var setupPrice=$('#setupPrice').val();
			if (setupPrice == '') {
				layer.alert('请输入安装费用');
				return;
			}
			postData=postData + "&setupPrice=" + setupPrice;
		}
		
			
		var itemType= $("input[name='itemType']:checked").val();
		if(itemType!=undefined){
			postData=postData + "&itemType=" + itemType;
		}
		
		var deliveryType= $("input[name='deliveryType']:checked").val();
		if(deliveryType!=undefined){
			postData=postData + "&deliveryType=" + deliveryType;
		}
		

		var itemUrl = $('#itemUrl').val();
		if (itemUrl == '') {
			layer.alert('请输入图片名称');
			return;
		}
		postData = postData + "&itemUrl=" + itemUrl;
		
		var itemDesc = $('#itemDesc').val();
		if (itemDesc == '') {
			layer.alert('请输入商品描述');
			return;
		}
		postData = postData + "&itemDesc=" + itemDesc;
		
		if(itemType=='0'){
			var email = $('#email').val();
			if (email == '') {
				layer.alert('请输入邮箱');
				return;
			}
			postData = postData + "&email=" + email;
		}

		layer.load(1, {
			shade : [ 0.5, '#fff' ]
		});
		//alert(postData);
		$.ajax({
			type : "POST",
			url : "save",
			data : postData,
			contentType : "application/x-www-form-urlencoded;charset=UTF-8",
			async : true, // 同步  true 异步。默认是异步
			dataType : 'json',
			error : function(resultdata) {
				layer.closeAll();
			},
			success : function(resultdata) {
				layer.closeAll();
				if (resultdata.returnCode == "0000") {
					layer.alert('操作成功', {
						icon : 1
					}, function() {
						parent.editReturn();
						//layer.closeAll(); 
						//layer.closeAll();
						//window.location.href="${pageContext.request.contextPath}/distrbutor/inventory/index";
					});
				} else {
					layer.alert(resultdata.returnMessage);
				}
			}
		});
	}
	function backIndex() {
		parent.editReturn();
	}
</script>
<%@include file="../common/masterbottom.jsp"%>
